{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'choices': [{'message': {'content': '', 'role': 'assistant', 'tool_calls': [{'index': 0, 'id': 'call_baa489bcf2e546b7be4144', 'type': 'function', 'function': {'name': 'get_fault_detail', 'arguments': '{\"batch\": \"#2201\", \"fault\": \"侧围外板左翼子板区域局部开裂，长度约5mm，深度2mm；滑移线超标（对比极限样件+0.3mm）\", \"location\": \"侧围外板左翼子板区域\", \"productionLine\": \"A\"}'}}]}, 'finish_reason': 'tool_calls', 'index': 0, 'logprobs': None}], 'object': 'chat.completion', 'usage': {'prompt_tokens': 255, 'completion_tokens': 86, 'total_tokens': 341, 'prompt_tokens_details': {'cached_tokens': 0}}, 'created': 1751449726, 'system_fingerprint': None, 'model': 'qwen-plus', 'id': 'chatcmpl-d85ca08f-1792-963a-bf1e-0ad4472d0ea3'}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "# 您的API Key\n",
    "API_KEY = \"sk-XXXXX\"\n",
    "\n",
    "url = \"https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions\"\n",
    "\n",
    "headers = {\n",
    "    'Authorization': f'Bearer {API_KEY}',\n",
    "    'Content-Type': 'application/json'\n",
    "}\n",
    "\n",
    "data = {\n",
    "    \"model\": \"qwen-plus\",\n",
    "    \"messages\": [\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": \"产线A, 批次#2201, 侧围外板左翼子板区域局部开裂，长度约5mm，深度2mm；滑移线超标（对比极限样件+0.3mm）\"\n",
    "        }\n",
    "    ],\n",
    "    \"tools\": [\n",
    "        {\n",
    "            \"type\": \"function\",\n",
    "            \"function\": {\n",
    "                \"name\": \"get_fault_detail\",\n",
    "                \"description\": \"根据故障描述提取其中的信息\",\n",
    "                \"parameters\": {\n",
    "                    \"type\": \"object\",\n",
    "                    \"properties\": {\n",
    "                        \"productionLine\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"产线\"\n",
    "                        },\n",
    "                        \"batch\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"批次\"\n",
    "                        },\n",
    "                        \"location\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"位置\"\n",
    "                        },\n",
    "                        \"fault\": {\n",
    "                            \"type\": \"string\",\n",
    "                            \"description\": \"故障\"\n",
    "                        }\n",
    "                    },\n",
    "                    \"required\": [\n",
    "                        \"location\"\n",
    "                    ]\n",
    "                }\n",
    "            }\n",
    "        }\n",
    "    ],\n",
    "    \"tool_choice\": \"auto\"\n",
    "}\n",
    "\n",
    "response = requests.post(url, headers=headers, json=data)\n",
    "print(response.json())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
